package com.bjim.model;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.bjim.common.BaseModel;
import cn.dreampie.orm.annotation.Table;

/**
 * 部门表映射类
 * @author chen
 *
 */
@Table(name="ts_dep",primaryKey="depid",generatedKey="")
public class Dep extends BaseModel<Dep> {
	public static Dep dao=new Dep();
	
	
	/*
	 * 获取部门所有联系人
	 */
	public List<User> findEmps(){
		List<User> users=User.dao.find("select account, userid,username,role,portrait_uri,depid,hrEmployee from ts_user where depid=?", this.getStr("depid"));
		for(User user:users){
			user.put("hrEmployee", JSONObject.parse(user.getStr("hrEmployee")));
		}
		return users;
	}
	
	/**
	 * 获取所有部门
	 * @return
	 */
	public List<Dep> queryAlldep(){
		return find("select * from ts_dep order by depcode");
	}
	/**
	 * 根据上级部门查找下级部门
	 * @return
	 */
	
	public List<Dep> finddeps() {
		List<Dep> deps=findBy("parentdepid=?", this.getStr("depid"));
		return deps;
	}


	public List<Dep> findBydepname(String depname) {
		List<Dep> deps=findBy("depname like ?", "%"+depname+"%");
		return deps;
	}
}
